package com.ruoyi.expressList.mapper;

import java.util.List;

import com.ruoyi.expressList.domain.ExpressAuth;
import com.ruoyi.expressList.domain.ExpressList;
import com.ruoyi.expressList.domain.ExpressDetial;
import com.ruoyi.expressList.domain.ExpressSystemMassage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 公告Mapper接口
 *
 * @author ruoyi
 * @date 2024-08-22
 */
public interface ExpressListMapper {

    @Select("select * from express_list l join express_detial d on l.register_ip=d.register_ip where is_vip=1")
    List<ExpressDetial> selectExpressListList(ExpressDetial expressList);

    @Select("select * from express_list l join express_detial d on l.register_ip=d.register_ip where is_vip=2")
    List<ExpressDetial> selectExpressListMemberList(ExpressDetial expressList);

    @Select("select * from express_list l join express_detial d on l.register_ip=d.register_ip where l.id=#{id}")
    ExpressDetial getDetialList(@Param("id") Long id);

    @Select("select * from express_list l join express_detial d on l.register_ip=d.register_ip where l.phone=#{phone}")
    ExpressDetial getDetialListPhone(@Param("phone") String phone);

    @Update("update express_detial set status=2 where register_ip=#{id}")
    int updateStatusFalse(@Param("id") Long id);

    @Update("update express_detial set status=1 where register_ip=#{id}")
    int updateStatusTrue(@Param("id") Long id);

    @Select("select * from express_list where id=#{id}")
    ExpressList selectById(Long id);

    @Update("update express_list set password=#{password} where id=#{id}")
    int resetPassword(ExpressList expressList);

    @Update("update express_list set pay_password=#{payPassword},pay_password_status=#{payPasswordStatus} where id=#{id}")
    int sernullPayPassword(ExpressList expressList);

    //根据id差行
    @Select("select * from express_detial where id=#{id}")
    ExpressDetial selectDetialById(Long id);

    //修改密码状态
    @Update("update express_list set pay_password_status=#{payPasswordStatus} where id=#{id}")
    void updateDetialPayPasswordStatus(ExpressDetial expressDetial);

    @Update("update express_detial set account_status=1 where register_ip=#{id}")
    int updateAccountStatusTrue(Long id);

    @Update("update express_detial set account_status=2 where register_ip=#{id}")
    int updateAccountStatusFalse(Long id);

    @Insert("insert into express_list (name,area_code,phone,post_company,create_date,is_del,is_vip,register_ip,register_type) values (#{name},#{areaCode},#{phone},#{postCompany},#{createDate},#{isDel},#{isVip},#{registerIp},#{registerType})")
    int expressAdd(ExpressList expressList);

    //    @Select("select * from express_auth a join express_detial d on a.id=d.pid join express_list l on l.id=a.id")
    @Select("select * from express_list l  join express_detial d on l.register_ip=d.register_ip join express_auth a on l.register_ip=a.id")
    List<ExpressAuth> authList(ExpressAuth expressAuth);

    @Select("select * from express_auth where iid=#{iid} and id=#{id}")
    ExpressAuth selectAuthByid(@Param("id") Long id, @Param("iid") Long iid);

    @Update("update express_auth set statusa=#{statusa},pass_date=#{passDate} where iid=#{iid}")
    int updateAuthStatus(ExpressAuth expressAuth);

    @Update("update express_auth set statusa=3,refuse_cn=#{expressAuth.refuseCn},refuse_en=#{expressAuth.refuseEn},pass_date=#{expressAuth.passDate} where id=#{expressAuth.registerIp} and iid=#{expressAuth.iid}")
    int updateRefuseReason(@Param("expressAuth") ExpressAuth expressAuth);

    @Select("select * from express_auth a join express_list l on l.register_ip=a.id join express_detial d on l.register_ip=d.register_ip where a.id=#{id} and a.iid=#{iid}")
    ExpressAuth getAuthDetialList(@Param("id") Long id, @Param("iid") Integer iid);

    //    @Select("select * from express_system_message where register_ip=#{id}")
//    ExpressSystemMassage selectSystemMessageByRegisterIp(Long id);
    @Insert("insert into express_system_message(register_ip,create_date,content) values (#{registerIp},#{createDate},#{content})")
    int insertSystemMessage(ExpressSystemMassage ex);

    @Select("select * from express_list where register_ip=#{id}")
    ExpressList getAuthById(Long id);

    @Update("update express_list set express_auth_status=#{expressAuthStatus} where register_ip=#{registerIp}")
    void updateAuthByid(ExpressList expressList);

    @Update("update express_list set real_name_status=#{realNameStatus} where register_ip=#{registerIp}")
    void updateRealNameAuthByid(ExpressList expressList);

    @Insert("insert into express_detial(register_ip,create_date,status) values (#{registerIp},#{createDate},#{status})")
    void expressAddDetialRegisterIp(ExpressDetial expressDetial);


    @Select("select count(*) num\n" +
            "from express_list")
    Integer getNum();

    @Select("select count(*) num\n" +
            "from express_list\n" +
            "where is_vip=1")
    Integer getVipNum();

    @Select("select count(*) num\n" +
            "from express_list\n" +
            "where is_vip=2")
    Integer getCourierNum();

    @Select("SELECT COUNT(*) AS num\n" +
            "FROM express_list\n" +
            "WHERE DATE(create_date) = CURDATE() - INTERVAL 1 DAY")
    Integer getNewAddNum();

    @Select("select count(*) num\n" +
            "from express_list\n" +
            "where is_vip = 1\n" +
            "  and DATE(create_date) = CURDATE() - INTERVAL 1 DAY")
    Integer getNewAddVipNum();

    @Select("select count(*) num\n" +
            "from express_list\n" +
            "where is_vip = 2\n" +
            "  and DATE(create_date) = CURDATE() - INTERVAL 1 DAY")
    Integer getNewAddCourierNum();
}
